import cn.sh.yhk.Application;
import cn.sh.yhk.mapper.InviteBidsMapper;
import cn.sh.yhk.model.InviteBidsExample;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class InputKafka {

    @Autowired
    InviteBidsMapper inviteBidsMapper;

    @Autowired
    KafkaTemplate<String, Object> kafkaTemplate;


    @Test
    public void doTest() throws Exception {

        inviteBidsMapper.selectByExample(new InviteBidsExample()).stream().parallel().forEach(inviteBids -> {
            try {
                kafkaTemplate.send("test1", new ObjectMapper().writeValueAsString(inviteBids));

            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        });

    }


//    public static void main(String[] args) throws Exception {
//        inputData();
//    }
}